Run Event Preset
Description
The run_event_preset
function triggers the execution of a specific event preset based on the provided preset ID. It sends a POST
request to the server to run the event preset and returns the results of the operation. The function returns a WebServiceResult
object containing the HTTP response code, response string, and parsed JSON data from the server.
Function Signature:
def run_event_preset(ws_config: WebServiceConfig, event_preset_id: int) -> WebServiceResult:
Parameters
- ws_config (WebServiceConfig): Configuration object containing the base URL and other settings for the web service.
- event_preset_id (int): The ID of the event preset to be run.
Returns
- WebServiceResult: An object containing the result of the web service request:
http_response_code
: The HTTP response code returned by the web service (e.g., 200 for success).http_response_string
: The raw response string from the web service.json_data
: The parsed JSON response from the web service, orNone
if the response could not be parsed.code
: A status code (0 for success, -1 for failure).description
: A description of any error that occurred during the operation.
Example Usage
ws_config = WebServiceConfig(base_url="https://api.actionstreamer.com")
event_preset_id = 101
result = run_event_preset(ws_config, event_preset_id)
print(result.http_response_code)
print(result.json_data)
Behavior
- Sends a
POST
request to the server to trigger the specified event preset using the providedevent_preset_id
. - The server response is captured, including the HTTP status code and response content.
- The response is parsed into a
WebServiceResult
object, which contains the response code, string, and parsed JSON data. - In case of an error, the exception is handled, and the error message is captured and returned in the result.
Error Handling
- General Exception: Any errors during the request or while processing the response are caught and logged.
- Exception Information: The function prints the filename and line number for easier debugging when an exception occurs.